#include <stdio.h>

double atod(char s[])
{
    if (s==NULL) return 0;
    int i=0, sign=1, esign=1, deciFlag=0;
    double ret=0, e=0, decimal=0;
    while (s[i]!='e'&&s[i]!='\0')
    {
        if (s[i]=='-') sign=-1;
        else if (s[i]=='+') sign=1;
        else if (s[i]=='.') deciFlag=1;
        else if (deciFlag)
            decimal=decimal*10+s[i]-'0';
        else
            ret=ret*10+s[i]-'0';
        i++;
    }
    while (decimal>=1) decimal*=0.1;
    ret+=decimal;
    i++;
    while (s[i])
    {
        if (s[i]=='-') esign=0;
        else
            e=e*10+(s[i]-'0');
        i++;
    }
    for (i=0; i<e; i++)
        ret*=(esign?10:0.1);
    ret*=sign;
    return ret;
}
/* test 2025-01-10-14:11
 * Please input a string:>123456.9e-6
 * The result is 0.123457.
 *
 * Process returned 0 (0x0)   execution time : 7.911 s
 * Press any key to continue.
 */

int main()
{
    double ret = 0;
    char s[20] = {0};
    printf("Please input a string:>");
    scanf("%s", s);
    ret=atod(s);
    printf("The result is %lf.\n", ret);
    return 0;
}

/* Please input a string:>1e4
 * The result is 10000.000000.
 *
 * Process returned 0 (0x0)   execution time : 9.329 s
 * Press any key to continue.
 *
 * Please input a string:>-1.46e-4
 * The result is -0.000146.
 *
 * Process returned 0 (0x0)   execution time : 15.504 s
 * Press any key to continue. */
/* [Test1]2025/01/11/12:45
 * Please input a string:>+123.456
 * The result is 123.456000.
 *
 * Process returned 0 (0x0)   execution time : 9.550 s
 * Press any key to continue. */
